package Easy;
// 69.x的平方根
public class Solution69 {
    public static int mySqrt(int x) {
        /**
         * 面试的时候肯定是不让直接用sqrt的
         * int sqrt = (int) Math.sqrt((double) x);
         * return sqrt;
         */
        long p = x;
        while (p*p>x){
            p/=2;
        }
        while (p*p<x){
            p++;
        }
        if(p*p==x)
            return (int)p;
        return (int)p-1;
    }

    public static void main(String[] args) {
        System.out.println(mySqrt(2112381972));
        System.out.println(Math.sqrt(2112381972));
    }
}
